class Promise {
  promiseState = "ing";
  promiseResult = null;
  constructor(callback) {
    let resolve = (date) => {
      if (this.promiseState !== "ing") return;
      this.promiseState = "success";
      this.promiseResult = date;
    };
    let reject = (date) => {
      if (this.promiseState !== "ing") return;
      this.promiseState = "error";
      this.promiseResult = date;
    };
    callback(resolve, reject);
  }
}

Promise.prototype.then = function (fn1, fn2) {
  if (this.promiseState === "success") {
    fn1(this.promiseResult);
  }
  if (this.promiseState === "error") {
    fn2(this.promiseResult);
  }
};
const p = new Promise((resolve, reject) => {
  resolve(11);
  reject(22);
});
console.log(p);
p.then(
  (res) => {
    console.log("success", res);
  },
  (err) => {
    console.log("error", err);
  }
);